package com.elitel.frame.main.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

	@Bean
	public Docket buildSingleDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("singleTableServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/singleServer/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}
	
	@Bean
	public Docket buildMultipleDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("executeSqlServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/multipleServer/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}
	
	@Bean
	public Docket buildMasterDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("masterConfigServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/extMasterServer/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}
	
	@Bean
	public Docket buildTreeConfigDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("treeconfigServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/execute/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}

	@Bean
	public Docket buildSearchDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("searchServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/searchServer/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}

	@Bean
	public Docket buildsingleEditDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("tableEditServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/singleEditServer/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}

	@Bean
	public Docket buildMoreJoinDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("moreTableServer")
				.apiInfo(buildApiInf())
				.select()
				.apis(RequestHandlerSelectors
						.basePackage("com.elitel.frame.business.controller"))
//				.apis(RequestHandlerSelectors.any()) // 对所有api进行监控
				.paths(PathSelectors.regex("/business/moreJoinTable/.*"))//过滤的接口
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo buildApiInf() {

		return new ApiInfoBuilder()
				.title("艾力泰尔数据框架API接口文档")
				.description("HTTP对外开放接口")
				.version("1.0")
				.build();

	}

}